<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <script src="../vue.js"></script>
    </head>

    <body>
        <div id="app">
            <button @click="num++">num加一</button>
            <h1>num: {{num}}</h1>
            <h1>plus后的num：{{plus}}</h1>
            <button @click="obj.name = 'lisi'">修改obj.name</button>
        </div>
        <script>
            Vue.config.productionTip = false;

            const vm = new Vue({
                el: "#app",
                data() {
                    return {
                        num: 1,
                        obj: {
                            name: "wang",
                            age: 1,
                        },
                    };
                },
                computed: {
                    plus() {
                        return this.num + 3
                    }
                },
                watch: {
                    num: {
                        handler() {
                            console.log("修改了num");
                        },
                    },
                    obj: {
                        // immediate: true,
                        // deep: true,
                        handler() {
                            console.log("监控obj");
                        },
                    },
                    plus: {
                        handler() {
                            console.log('监控了plus')
                        }
                    }
                },
            });
        </script>
    </body>
</html>
